import os
from datetime import datetime

def ensure_folder_exists(folder_path):
    if not os.path.exists(folder_path):
        try:
            os.makedirs(folder_path)
            print(f"文件夹 {folder_path} 已创建")
        except OSError as e:
            print(f"创建文件夹 {folder_path} 时出错: {e}")
    else:
        print(f"文件夹 {folder_path} 已存在")
        
        
def get_today_date():
    return datetime.now().strftime('%Y-%m-%d')


def search_data(s='财政'):
    paths = os.listdir('cache')
    filter_paths = [path for path in paths if path.endswith('.xlsx') and path.startswith(s)]
    today = get_today_date()
    filter_paths = [p for p in filter_paths if today in p]
    if len(filter_paths) == 0:
        print('没有找到今天的数据,是不是忘记下载数据了？')
        return None
    return filter_paths[0]

